#pragma once

#include <QtWidgets/QDialog>
#include "ui_QtWidgetsApplication1.h"
#include "../wke.h"
#include "QMiniBlink.h"
#include <xpack/json.h>

class QtWidgetsApplication1 : public QDialog
{
    Q_OBJECT

public:
    QtWidgetsApplication1(QDialog* parent = Q_NULLPTR);
    ~QtWidgetsApplication1();

    bool loadUrl(const QString &url);

Q_SIGNALS :
    void loadedData(double);


private:

    void initView();

    void initConnectEvent();

    static jsValue WKE_CALL_TYPE jsInitData(jsExecState es, void* vptr);
    static jsValue WKE_CALL_TYPE jsOnOk(jsExecState es, void* vptr);
    static jsValue WKE_CALL_TYPE jsOnCancel(jsExecState es, void* vptr);
    static jsValue WKE_CALL_TYPE jsLoadData(jsExecState es, void* vptr);

    void onBtnCancelClicked();
    void onBtnOKClicked();

    void loadData();

    void onLoadedData(double data);

private:
    Ui::QtWidgetsApplication1Class* ui;
    QMiniBlink* m_qMiniBlink;

    struct FormData
    {
        double contral_point_step;
        double total_area;
        double precision_level;
        int direction;
        int mode;
        bool is_point_cloud;
        XPACK(M(contral_point_step, total_area, precision_level, direction, mode, is_point_cloud));
    } m_lastInputData, m_formData;

    std::thread m_loadData;
};
